<!DOCTYPE html>
<html lang="zh-CN">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
	</head>

	<body>
		<div id="app">
			<h2>书的总价是：{{totalPrice}}</h2>
		</div>

		<script src="../lib/vue.js"></script>
		<script>
			let vm = new Vue({
				el: "#app",
				data: {
					book: [
						{ id: 110, name: "Unix", price: 119 },
						{ id: 111, name: "JavaScript", price: 105 },
						{ id: 112, name: "深入计算机原理", price: 98 },
						{ id: 113, name: "ES6入门", price: 87 }
					]
				},
				computed: {
					totalPrice() {
						return this.book.reduce((total, item) => {
							return (total += item.price);
						}, 0);
					}
				},
				methods: {}
			});
		</script>
	</body>
</html>
